package com.itmuch.cloud.feign;

import com.itmuch.cloud.entity.User;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class HystrixClientFallbackFactory implements FallbackFactory<UserFeignClient> {
    private static  final Logger logger = LoggerFactory.getLogger(HystrixClientFallbackFactory.class);
    @Override
    public UserFeignClient create(Throwable cause) {
        logger.debug(cause.getMessage());
        return new UserFeignClient() {
            @Override
            public User findById(Long id) {

                User user = new User();
                user.setName(cause.getMessage());
                return user;
            }

//        @Override
//        public User findById() {
//          return new findById("fallback; reason was: " + cause.getMessage());
//        }
        };
    }
}